using System;
using System.Web.Security;
using System.Web.Configuration;

namespace MoneyManagerPro.Host.IIS.MasterPages
{
    public partial class Default : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.User.Identity.IsAuthenticated)
            {
                MembershipUser mu = Membership.GetUser();

                lblUser.Text = mu.UserName;
                //lblRole.Text = Roles.GetRolesForUser()[0];
                lblTitle.Text = ConfigurationManager.ApplicationName;
                lblVersion.Text = "Version: " + ConfigurationManager.ApplicationVersion;

                if (!Page.IsPostBack)
                {
                    ddlThemes.SelectedValue = SessionHandler.SelectedTheme;
                }
            }
        }
        
        protected void menuMain_MenuItemDataBound(object sender, System.Web.UI.WebControls.MenuEventArgs e)
        {
            System.Web.SiteMapNode s = e.Item.DataItem as System.Web.SiteMapNode;
            string[] tokens = s.Description.Split('#');
            e.Item.ToolTip = tokens[0]; 
            e.Item.ImageUrl = "~/App_Themes/" + SessionHandler.SelectedTheme + "/Images/" + tokens[1];
        }
        
        protected void ddlThemes_SelectedIndexChanged(object sender, EventArgs e)
        {
            SessionHandler.SelectedTheme = ddlThemes.SelectedValue;
            Response.Redirect(this.Page.Request.Url.ToString());
        }
}
}